package com.wits.qso.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.wits.platform.dao.impl.BaseDaoImpl;
import com.wits.qso.dao.custom.CListDaoCustom;
import com.wits.qso.entity.CList;

/**
 * @author Ethan Lee
 */

@Component
public class CListDaoImpl extends BaseDaoImpl<CList, String> implements CListDaoCustom
{

	public CList findRoot() {
		CList result = null;
		try {
			result = (CList) em.createQuery( "FROM CList o WHERE o.fatherId IS NULL" ).getSingleResult();
		} catch (Throwable cause) {
		}

		return result;
	}

	public List<CList> findNode(CList cList) {
		Query query = em.createQuery( "FROM CList o WHERE o.fatherId = :cList" );
		query.setParameter( "cList", cList );

		return query.getResultList();
	}
	/**
	 * 根据cListId查询节点
	 * @param cListId
	 * @return
	 */
	public CList findNode(String cListId) {
		Query query = em.createQuery( "FROM CList o WHERE o.id = :cListId" );
		query.setParameter( "cListId", cListId );
		List<CList> cLists=query.getResultList();
		CList cList=cLists!=null?cLists.get(0):null;
		return cList;
	}
}
